<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<ul class="pagination">
    <c:if test="${pageBean.pageNum <= 1}">
        <li class="disabled"><span>上一页</span></li>
    </c:if>
    <c:if test="${pageBean.pageNum > 1}">
        <li>
            <a href="javascript:void(0);" onclick="page('${pageContext.request.contextPath}/${pageBean.url}','${pageBean.pageNum-1}','${pageSize}')">上一页</a>
        </li>
    </c:if>
<%--    默认最多只能显示12个页码--%>
    <c:if test="${pageBean.pageNum <7}">
        <c:forEach begin="1" end="${12>pageBean.pages?pageBean.pages:12}" var="index">
            <c:if test="${pageBean.pageNum == index}">
                <li class="active"><span>${index}</span></li>
            </c:if>
            <c:if test="${pageBean.pageNum != index}">
                <li>
                    <a href="javascript:void(0);" onclick="page('${pageContext.request.contextPath}/${pageBean.url}','${index}','${pageBean.pageSize}')">${index}</a>
                </li>
            </c:if>
        </c:forEach>
    </c:if>
    <c:if test="${pageBean.pageNum >= 7}">
        <c:forEach begin="${pageBean.pageNum-6}" end="${pageBean.pages-pageBean.pageNum>5?pageBean.pageNum+5:pageBean.pages}" var="index">
            <c:if test="${pageBean.pageNum == index}">
                <li class="active"><span>${index}</span></li>
            </c:if>
            <c:if test="${pageBean.pageNum != index}">
                <li>
                    <a href="javascript:void(0);" onclick="page('${pageContext.request.contextPath}/${pageBean.url}','${index}','${pageBean.pageSize}')">${index}</a>
                </li>
            </c:if>
        </c:forEach>
    </c:if>

    <c:if test="${pageBean.pageNum >= pageBean.pages}">
        <li class="disabled"><span>下一页</span></li>
    </c:if>
    <c:if test="${pageBean.pageNum < pageBean.pages}">
        <li>
            <a href="javascript:void(0);" onclick="page('${pageContext.request.contextPath}/${pageBean.url}','${pageBean.pageNum+1}','${pageBean.pageSize}')">下一页</a>
        </li>
    </c:if>
</ul>

<script>
    function page(url,pageNum,pageSize){
        let ss = $('#search-btn').html();
        let i1 = ss.indexOf("\"");
        let i2 = ss.lastIndexOf("\"");
        let searchKey = ss.substr(i1 + 1, i2 - i1 - 1);
        let searchValue = $("#search-value").val();
        let status = $("#status").val();

        document.location.href= url+"/"+pageNum+"/"+pageSize+"?searchKey="+searchKey+"&searchValue="+searchValue+"&s="+status;
    }
</script>
